// pages/invitation/invitation.js
const app = getApp(), core = require('../../utils/core'), util = require('../../utils/util');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabNumber:{tab_0: 0, tab_1: 0, tab_2: 0, tab_3: 0, tab_4: 0},
    query: {status:0},
    interviews: [],
    interviewsMore: {page:1},
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.tabNumber();
    this.fetch();
  },
  bindStatusChange:function(e) {
    this.setData({
      'query.status': e.currentTarget.dataset.status
    });
    this.refresh();
  },
  refresh: function () {
    this.setData({interviews:[],interviewsMore:{page:1}});
    this.tabNumber();
    this.fetch();
  },
  fetch() {
    util.fetch(this, '/xilujob.job_interview/company_list', this.data.query, 'interviewsMore', 'interviews', 'data');
  },

  bindFailInterview(event) {
    let index = event.currentTarget.dataset.index;
    let interview = this.data.interviews[index];
    wx.showModal({
      title: '提示',
      content: '确认面试不合格？',
      success: res=>{
        if (res.confirm) {
          core.post({
            url: 'xilujob.job_interview/multi_status/interview_id/'+interview.id, data: {status:3},
            success: ret => {
              this.setData({['interviews['+index+'].status']: ret.data.status});
            }
          });
        }
      }
    })
  },
  bindPassInterview(event) {
    let index = event.currentTarget.dataset.index;
    let interview = this.data.interviews[index];
    wx.showModal({
      title: '提示',
      content: '确认面试录取？',
      success: res=>{
        if (res.confirm) {
          core.post({
            url: 'xilujob.job_interview/multi_status/interview_id/'+interview.id, data: {status:4},
            success: ret => {
              this.setData({['interviews['+index+'].status']: ret.data.status});
            }
          });
        }
      }
    })
  },

  tabNumber() {
    var page = this;
    core.get({url: '/xilujob.job_interview/company_list_count',success(ret,response){page.setData({tabNumber:ret.data})}});
  }
});
